{% extends "base/base_width_left.html" %}
{#{% load pagination_tags %}#}

{% block flag %}server{% endblock %}
{% block path %}
    <a href="{% url 'server:list' %}" title="" class="tip-bottom">项目/节点管理</a>
    <a href="" title="" class="tip-bottom">{{ server.ip }}详情</a>
{% endblock %}
{% block style %}
    <style>
        .detail div {
            float: left;
            margin-left: 50px;
            border-bottom: 1px dashed lightgrey;
            width: 30%;
        }

        .detail div .name {
            color: #43c4f0;
        }

        .detail div .vaule {
            color: lightgrey;
        }
    </style>
{% endblock %}
{#{% block searchname %}searchaction{% endblock %}#}
{#{% block searchtip %}订单编号{% endblock %}#}

{% block container %}
    {{ block.super }}
{#    {% autopaginate play_books %}#}
{#    <ul class="nav nav-tabs">#}
{#        <li role="presentation" class="active"><a href="{% url 'product:product_list' %}">日志</a></li>#}
{#        <li role="presentation"><a href="{% url 'product:type_list' %}">剧本</a></li>#}
{#    </ul>#}
    <div hidediv="hide" class="center-block">
        {#        <div class="dropdown" style="display:inline">#}
        {#            <a class="btn btn-default dropdown-toggle" type="button" href="{% url 'server:editor' %}">#}
        {#                           创建#}
        {#            </a>#}
        {#        </div>#}
        {#        <a href="{% url 'product:product_form' %}" class="btn btn-primary">添 加</a>#}
    </div>
    <div class="panel panel-default">
        <!-- Default panel contents -->
        <div class="panel-heading">{{ server.ip }}详情</div>
        <div class="panel-body">
            <div class="detail">
                <div>
                    <p class="name">ip地址</p>
                    <p class="vaule">{{ server.ip }}</p>
                </div>
                <div>
                    <p class="name">端口号</p>
                    <p class="vaule">{{ server.port }}</p>
                </div>
                <div>
                    <p class="name">ipv4</p>
                    <p class="vaule">{% if server.ipv4 %}{{ server.ipv4 }}{% else %}未知{% endif %}</p>
                </div>
            </div>
            <div style="clear: both"></div>
            <div class="detail">
                <div>
                    <p class="name">服务器账户</p>
                    <p class="vaule">{{ server.ssh_user }}</p>
                </div>
                <div>
                    <p class="name">服务器密码</p>
                    <p class="vaule">{{ server.ssh_password }}</p>
                </div>
                <div>
                    <p class="name">cpu类型</p>
                    <p class="vaule">{% if server.cpu_type %}{{ server.cpu_type }}{% else %}未知{% endif %}</p>
                </div>
            </div>
            <div style="clear: both"></div>
            <div class="detail">
                <div>
                    <p class="name">cpu内核</p>
                    <p class="vaule">{% if server.cpu_total %}{{ server.cpu_total }}{% else %}未知{% endif %}</p>
                </div>
                <div>
                    <p class="name">操作系统类型</p>
                    <p class="vaule">{% if server.os_type %}{{ server.os_type }}{% else %}未知{% endif %}</p>
                </div>
                <div>
                    <p class="name">硬盘总量</p>
                    <p class="vaule">{% if server.disk_total %}{{ server.disk_total }}{% else %}未知{% endif %}</p>
                </div>
            </div>
            <div style="clear: both"></div>
            <div class="detail">
                <div>
                    <p class="name">硬盘挂载名及容量</p>
                    <p class="vaule">{% if server.disk_mount %}{{ server.disk_mount }}{% else %}未知{% endif %}</p>
                </div>
                <div>
                    <p class="name">服务器主机名</p>
                    <p class="vaule">{% if server.host_name %}{{ server.host_name }}{% else %}未知{% endif %}</p>
                </div>
                <div>
                    <p class="name">操作系统内核</p>
                    <p class="vaule">{% if server.os_kernel %}{{ server.os_kernel }}{% else %}未知{% endif %}</p>
                </div>
            </div>
            <div style="clear: both"></div>
            <div class="detail">
                <div>
                    <p class="name">服务器运行状态</p>
                    <p class="vaule">{{ server.status }}</p>
                </div>
                <div style="border-bottom: 0;margin-top: 15px;">
                    <a class="btn btn-default" href="{% url 'operation:list' %}?sid={{ server.id }}" >查看记录</a>
                    <a class="btn btn-default run" url="{% url 'playbooks:run'%}" >更新</a>
                </div>
                {#                    <div>#}
                {#                        <p class="name">操作系统内核</p>#}
                {#                        <p class="vaule">{% if server.cpu_type %}{{ server.cpu_type }}{% else %}未知{% endif %}</p>#}
                {#                    </div>#}
            </div>
        </div>
    </div>
{#    <ul class="nav nav-tabs">#}
{#        <li role="presentation" class="active operation"><a href="{% url 'product:product_list' %}">日志</a></li>#}
{#        <li role="presentation" class="playbook"><a href="{% url 'product:type_list' %}">剧本</a></li>#}
{#    </ul>#}
        <div hidediv="hide" class="table-responsive playbooks-content ">
        {% include 'server/playbooks.html' %}

        </div>
{% endblock %}
{% block footjs %}
    <script>
        $.ajaxSetup({
                    data: {csrfmiddlewaretoken: '{{ csrf_token }}'}
                });
       $('.run').on('click',function(){
           var url=$(this).attr('url');
           var sid={{ server.id }};
           $.post(url,{'sid':sid},function(data){
               if(data==1){
                   alert('已经运行剧本');
{#                   create_websocket();#}
                   time_lazy();
{#                   setInterval(create_websocket, 1000);#}
               }else{
                   alert('执行失败')
               }
           });
{#           location.reload();#}
       });
       $('.run_books').on('click',function(){
           var url=$(this).attr('url');
           var fid=$(this).parents('tr').find('.version').val();
           var url_all=url+'&fid='+fid;
           var sid={{ server.id }};
           $.post(url_all,{'sid':sid},function(data){
               if(data==1){
                   alert('剧本正在运行中');
                   time_lazy();
{#                    setInterval(create_websocket, 1000);#}
               }else{
                   alert('执行失败')
               }
           });
{#           location.reload();#}
       });
        $('.delete_relation').on('click',function(){
            var $this=$(this);
            var url=$this.attr('url');
            $.post(url,{'sid':{{ server.id }}},function(data){
                if(data['code']==1){
                    alert(data['msg']);
                    $this.parents('tr').remove();
                }else{
                    alert(data['msg']);
                }
            })
        })

    </script>
{% endblock %}
